<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>鑫多多</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/icons-extra.css" rel="stylesheet" />
		<link href="../css/iconfont.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />

		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/service/evaluateListService.js"></script>
	</head>

	<body ng-app="mainApp" ng-controller="evaluateListCtrl">

		<header class="mui-bar mui-bar-nav mui-bar-detail mui-bar-in">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">产品评价</h1>
			<a class="mui-icon mui-pull-right right" ng-click="publish()">发布</a>
		</header>
		<!-- 主页面内容容器 -->
		<div class="mui-content">
			<!-- 主界面具体展示内容 -->
			<ul class="mui-table-view cart comments_input">
				<li class="mui-table-view-cell mui-media" ng-repeat="goods in goodsList">

					<div class="mui-right">

						<div class="mui-pull-left">
							<a href="product_detail.html">
								<a href="#"><img ng-if="goods.iconUrl!=undefined&&goods.iconUrl!=''" class="mui-media-object" src="{{baseUrl+'/dapi/download/getImageIO?imgUrl='+goods.iconUrl|getImgUrl}}" ></a>
								<a href="#"><img ng-if="goods.iconUrl==undefined||goods.iconUrl==''" class="mui-media-object" ng-src="../images/goodsDefault.gif"></a>
							</a>
						</div>
						<div class="mui-media-body">
							<h5><a href="product_detail.html">{{goods.goodsTitle}} 约{{goods.perWeight}}g</a></h5>

						</div>

					</div>

					<div class="mui-input-row">
						<textarea id="{{goods.goodsId}}" rows="5" placeholder="请输入评价" ng-model="content"></textarea>
					</div>
				</li>
			</ul>

		</div>
		<script type="text/javascript">
			mui.init();
			mui('.bottomPopover').popover('toggle'); //show hide toggle
			mainApp.controller('evaluateListCtrl', function($scope, $http, evaluateListService) {
				$scope.baseUrl = baseUrl;
				(function($) {
					$.plusReady(function() {
						var self = plus.webview.currentWebview();
						var orderId = self.orderId;
						evaluateListService.getOrderById(orderId, function(data) {
							$scope.order=data.data;
							$scope.goodsList = data.data.goods;
							angular.forEach($scope.goodsList, function(goods) {
								evaluateListService.getEvaluate(orderId,goods.goodsId,function(data){
									$scope.evaluate=data.data;
									if($scope.evaluate != null&&$scope.evaluate !=""){
										document.getElementById(goods.goodsId).innerHTML=$scope.evaluate.content;
									}
								},error);
							});
						}, error)
						
					});
				})(mui);
				
				$scope.publish=function(){
					var goods=$scope.order.goods;
					var orderId=$scope.order.orderId;
					var list=[];
					for(var i=0;i<goods.length;i++){
						var content=document.getElementById(goods[i].goodsId).value;
						$scope.evaluate={"orderId":orderId,"goodsId":goods[i].goodsId ,"content":content};
						if(content!=null&&content!=""){
							list.push($scope.evaluate);
						}
					}
					evaluateListService.addEvaluate(list,function(data){
						mui.alert("评价成功！");
						mui.back();
					},error);
				};
			});
		</script>
	</body>
</html>